﻿//
// © Algobox Ltd - Benn Eichhorn
//
using System;
using System.Collections.Generic;
using System.Text;

namespace Algobox.Toolbox.Collections
{
    public class PriceSeries : IList<decimal>, ICollection<decimal>, IEnumerable<decimal>
    {
        public PriceSeries()
        {
                        
        }


        const int ARRAY_SIZE = 100;

        List<decimal> _list = new List<decimal>();
        
        long _arrayIndex = 0;
        double[] _array = new double[ARRAY_SIZE];


        #region ICollection<decimal> Members

        public int Count
        {
            get { return _list.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public void Add(decimal item)
        {
            if (_arrayIndex == _array.Length)
                Array.Resize<double>(ref _array, _array.Length + ARRAY_SIZE);

            _array.SetValue((double)item, _arrayIndex++);

            _list.Add(item);
        }

        public void Clear()
        {
            _array = new double[ARRAY_SIZE];
            _list.Clear();
        }

        public bool Contains(decimal item)
        {
            return _list.Contains(item);
        }

        public void CopyTo(decimal[] array, int arrayIndex)
        {
            _list.CopyTo(array, arrayIndex);
        }

        public bool Remove(decimal item)
        {
            return _list.Remove(item);
        }

        #endregion

        #region IEnumerable<decimal> Members

        public IEnumerator<decimal> GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        #endregion

        #region IList<decimal> Members

        public int IndexOf(decimal item)
        {
            return _list.IndexOf(item);
        }

        public void Insert(int index, decimal item)
        {
            _list.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            _list.RemoveAt(index);
        }

        public decimal this[int index]
        {
            get
            {
                return _list[index]; ;
            }
            set
            {
                _list[index] = value;
            }
        }

        #endregion
    }
}
